package com.bdqn.student.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.student.entity.Student;
import com.bdqn.student.service.StudentService;
import com.bdqn.student.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    StudentService studentService;

    //分页带条件查询
    @GetMapping
    public ResultVo page(String studentname, @RequestParam(defaultValue = "1") Integer pageNum ){
        Page<Student> studentPage= studentService.getPage(studentname,pageNum);
        return ResultVo.success("",studentPage);
    }

    //增 或者修改

    @PostMapping
    public ResultVo addOrUpdate(@RequestBody Student student){
        studentService.saveOrUpdate(student);
        return ResultVo.success("操作成功",null);
    }
    //删除
    @DeleteMapping("/{id}")
    public  ResultVo del(@PathVariable Integer id){
        studentService.removeById(id);
        return ResultVo.success("操作成功",null);
    }
}
